package cn.edu.nju.bankaccount.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.edu.nju.bankaccount.dao.DaoHelper;
import cn.edu.nju.bankaccount.dao.UserDao;
import cn.edu.nju.bankaccount.model.Account;
import cn.edu.nju.bankaccount.model.User;

public class UserDaoImpl implements UserDao{
	private static UserDaoImpl userDao=new UserDaoImpl();
	private static DaoHelper daoHelper=DaoHelperImpl.getBaseDaoInstance();
	
	public static UserDaoImpl getInstance()
	{
		return userDao;
	}
	public List findAll() {
		return null;
	}

	public User findById(String id) {
		Connection con=daoHelper.getConnection();
		PreparedStatement stmt=null;
		ResultSet result=null;
		String sql = "select * from `user` where id="+id;
		System.out.println(sql);
		User user = null;
		try 
		{
			stmt=con.prepareStatement(sql);
			result=stmt.executeQuery();
			while(result.next())
			{
				user = new User();
				user.setId(result.getInt("id"));
				user.setUsername(result.getString("username"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		finally
		{
			daoHelper.closeAll(con, stmt, result);
		}
		return user;
	}

	public void save(User user) {
		
	}

}
